﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Model.WaiGaoQiao;
using WaiGaoQiaoWeb.Models;
using WaiGaoQiaoWeb.JsonEntities;

namespace WaiGaoQiaoWeb.Controllers
{
    public class SporadicInfoSelController : Controller
    {
        private SporadicInfoSelInfo invinfo = new SporadicInfoSelInfo(true);

        public ActionResult SporadicInfoSelIndex()
        {
            return View();
        }

        /// <summary>
        /// 获取零星物品库存列表
        /// </summary>
        /// <param name="pvm"></param>
        /// <returns></returns>
        public ActionResult GetSporadicInfoSelList(PageVM pvm)
        {
            string query = " 1=1 ";
            if (string.IsNullOrEmpty(pvm.query))
            {
                query = " and 1=1";
            }
            else
            {
                string param = pvm.query.ToString();
                query = " and GoodsName like'%" + param + "%'";
            }
            IList<SporadicInfoSelInfo> invlist = invinfo.SelSporadicInfoSelInfo(pvm.rp, pvm.page, query);
            JsonFlexiGridData jfgd = new JsonFlexiGridData();
            jfgd.page = pvm.page;
            jfgd.total = invinfo._SporadicInfoSelcount;
            List<string> v;
            foreach (SporadicInfoSelInfo item in invlist)
            {
                #region
                v = new List<string>();
                v.Add(item.GoodsNo.ToString());
                v.Add(item.GoodsName);
                v.Add(item.STOCKS_COUNT.ToString());
                #endregion
                FlexiGridRow fgr = new FlexiGridRow()
                {
                    id = item.GoodsNo.ToString(),
                    cell = v
                };
                jfgd.rows.Add(fgr);
            }
            return Json(jfgd);
        }
    }
}
